package com.gitee.feizns.web.utils;

/**
 * @author feizns
 * @since 2019/6/25
 */
public abstract class StringUtils {

    /**
     * 在保证指定字符量的前提下填充前缀
     * @param original
     * @param prefix
     * @param len
     * @return
     */
    public static String fillPrefix(String original, char prefix, int len) {
        StringBuilder ret = new StringBuilder(original);
        int diff = len - original.length();
        for (int i = 0; i < diff; i++) {
            ret.insert(0, prefix);
        }
        return ret.toString();
    }

    public static String fillPrefixZero(String original, int len) {
        return fillPrefix(original, '0', len);
    }

    public static char[] toChars(StringBuilder sb) {
        char[] ret = new char[sb.length()];
        sb.getChars(0, ret.length, ret, 0);
        return ret;
    }

    public static String trim(String str) {
        return str != null ? str.trim() : null;
    }

}
